import java.io.File;
import java.io.IOException;

public class fileDemo3 {
    //文件的删除
    public static void main1(String[] args) throws IOException {
        File file = new File("helloworld.txt");
        file.createNewFile();
        //根据 File 对象，删除该文件。成功删除后返回 true
        try {
            Thread.sleep(3000);
            System.out.println(file.delete());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
    public static void main(String[] args) throws IOException, InterruptedException {
        File file = new File("hellowrld.txt");
        file.createNewFile();
        System.out.println("文件创建成功");
        Thread.sleep(3000);
//      根据 File 对象，标注文件将被删除，删除动作会到JVM 运行结束时才会进行
        file.deleteOnExit();
        System.out.println("把文件标记位退出则删除状态");
        Thread.sleep(3000);
    }
}
